package client;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
 * Public class. Creates first GUI. It shows the fields to connect.
 * @author agurgul
 *
 */
public class GUIThread implements Runnable {
	
	
	@Override
	public void run() {
		createAndShowFirstFrame();

	}
	private void createAndShowFirstFrame(){
		Client.startFrame = new JFrame("Client");
		Client.startFrame.setSize(600, 400);
		Client.startFrame.setLocation(200, 200);
		Client.startFrame.setResizable(false);
		Client.startFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		Client.portLabel = new JLabel();
		Client.portLabel.setPreferredSize(new Dimension(250, 100));
		Client.portLabel.setText("Port: ");
		
		Client.adressLabel = new JLabel();
		Client.adressLabel.setPreferredSize(new Dimension(250, 100));
		Client.adressLabel.setText("Adress: ");
		
		Client.connectButton = new JButton();
		Client.connectButton.setPreferredSize(new Dimension(250, 100));
		Client.connectButton.setText("Connect");
		Client.connectButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				Client.connect();
				System.out.println( "Cokolwiek1" );
				Client.play();
				System.out.println( "Cokolwiek2" );
			}
		});
		
		Client.exitButton = new JButton();
		Client.exitButton.setPreferredSize(new Dimension(250, 100));
		Client.exitButton.setText("Exit");
		Client.exitButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e2) {
				System.exit(1);
			}
		});
		
		Client.portIn = new JTextField();
		Client.portIn.setPreferredSize(new Dimension(250, 100));
		
		Client.adressIn = new JTextField();
		Client.adressIn.setPreferredSize(new Dimension(250, 100));
		
		Client.mainPanel = new JPanel(new GridLayout(3, 2));
		Client.mainPanel.add(Client.adressLabel);
		Client.mainPanel.add(Client.adressIn);
		Client.mainPanel.add(Client.portLabel);
		Client.mainPanel.add(Client.portIn);
		Client.mainPanel.add(Client.connectButton);
		Client.mainPanel.add(Client.exitButton);
		Client.startFrame.add(Client.mainPanel);
		Client.startFrame.setVisible(true);
		
	}

}
